#coding:utf-8
'''
create on 2017-04-20
@author:sandy
'''
import logging
from pycommon import Const
from pycommon import Pack as packet
import CenterBuild
import BillFactory


def cmdLogin(bill,pkt):
    sid = packet.unpack("H",pkt)
    logging.debug("BillParse cmdLogin pid = %d",sid)
    oldClient = BillFactory.instance.getBillSrvBySid(sid)
    if oldClient == None:
        logging.debug(u'sid=%d register sucess',sid)
        bill.sendPacket(CenterBuild.billLoginCenterSucess(Const.ERR_OK))
        bill.onLogin(sid)
    else:
        logging.debug(u'sid=%d register Failed,server is exist',sid)
        bill.sendPacket(CenterBuild.billLoginCenterSucess(Const.ERR_SERVER_EXIST))
    pass

    pass

def cmdPaySuc(bill,pkt):
    code = packet.unpack("H",pkt)
    logging.debug("BillParse cmdPaySuc code=%d",code)
    pass

def cmdPayFail(bill,pkt):
    code = packet.unpack("H",pkt)
    logging.debug("BillParse cmdPayFail code=%d",code)
    pass

#================================Ð­Òé±í===========================================
    
__cmdTable = {
                Const.CMD_BILL2CT_LOGIN                : cmdLogin,
                Const.CMD_BILL2CT_PAY_SUCESS           : cmdPaySuc,
                Const.CMD_BILL2CT_PAY_FAILED           : cmdPayFail
             } 

def parse(bill, cmd, pkt):
    logging.debug(u"BillParse cmd = %d",cmd)
    func = __cmdTable.get(cmd)
    if not func :
        logging.error(u"cmd is not exit");
    func(bill, pkt)    
    
if __name__ == '__main__':
    pass